<?php

namespace App\Containers\AppSection\BankDetail\Actions;

use App\Containers\AppSection\BankDetail\Models\BankDetail;
use App\Containers\AppSection\BankDetail\Tasks\CreateBankDetailTask;
use App\Containers\AppSection\BankDetail\UI\API\Requests\CreateBankDetailRequest;
use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Ship\Parents\Actions\Action;

class CreateBankDetailAction extends Action
{
    public function run(CreateBankDetailRequest $request): BankDetail
    {
        $data = $request->sanitizeInput([
            'name',
            'bik',
            'correspondent_account',
            'inn',
            'checking_account',
            'profile_id' => $request->profile()->id
        ]);

        $bankDetail = app(CreateBankDetailTask::class)->run($data);

        app(CreateLogTask::class)->run($request->profile()->id, "Банковские реквизиты №{$bankDetail->id} добавлены", 'bankDetail');

        return $bankDetail;
    }
}
